<!-- 机构编辑弹窗 -->
<template>
  <ele-modal
    width="80%"
    :visible="visible"
    :close-on-click-modal="false"
    custom-class="ele-dialog-form"
    :title="'审核'"
    @update:visible="updateVisible"
  >
    <el-form ref="form" :model="form"  label-width="130px">
      <el-row :gutter="15">
        <el-col :sm="8">
          <el-form-item label="账号:">
            <span>{{ info.telphone }}</span>
          </el-form-item>
          <el-form-item label="姓名:" v-if="info.info && info.info.type == 1">
            <span>{{ info.info.name }}</span>
          </el-form-item>
          <el-form-item label="身份证号:" v-if="info.info && info.info.type == 1">
            <span>{{ info.info.id_card_no }}</span>
          </el-form-item>
          <el-form-item label="身份证姓名:" v-if="info.info && info.info.type == 1">
            <span>{{ info.info.id_card_name }}</span>
          </el-form-item>

          <el-form-item label="身份证省市区:" v-if="info.info && info.info.type == 1">
            <span>{{ info.info.id_card_address }}</span>
          </el-form-item>

          <el-form-item label="身份证详细地址:" v-if="info.info && info.info.type == 1">
            <span>{{ info.info.id_card_detail  }}</span>
          </el-form-item>

          <el-form-item label="企业全称:" v-if="info.info && info.info.type == 2">
            <span>{{ info.info.company_name }}</span>
          </el-form-item>

          <el-form-item label="企业联系人名称:" v-if="info.info && info.info.type == 2">
            <span>{{ info.info.contact_name }}</span>
          </el-form-item>

          <el-form-item label="企业联系人电话:" v-if="info.info && info.info.type == 2">
            <span>{{ info.info.contact_phone }}</span>
          </el-form-item>

          <el-form-item label="企业地址:" v-if="info.info && info.info.type == 2">
            <span>{{ info.info.company_address }}</span>
          </el-form-item>

          <el-form-item label="企业详细地址:" v-if="info.info && info.info.type == 2">
            <span>{{ info.info.company_detail }}</span>
          </el-form-item>
        </el-col>
        <el-col :sm="8">
          <el-form-item label="申请类型:" v-if="info.info">
            <el-tag v-if="info.info && info.info.type == 1" type="success" effect="light">个人资质</el-tag>
            <el-tag v-if="info.info && info.info.type == 2" type="primary" effect="light">企业资质</el-tag>
          </el-form-item>
          <el-form-item label="身份证正面:" v-if="info.info && info.info.type == 1">
            <el-image
              style="width: 100px; height: 100px"
              :src="info.info.id_card_front" 
              :preview-src-list="front"
              :zIndex="9999"
            />
          </el-form-item>
          <el-form-item label="身份证反面:" v-if="info.info && info.info.type == 1">
            <el-image
              style="width: 100px; height: 100px"
              :src="info.info.id_card_verso" 
              :preview-src-list="verso"
              :zIndex="9999"
            />
          </el-form-item>


          <el-form-item label="营业执照编号:" v-if="info.info && info.info.type == 2">
            <span>{{ info.info.business_no }}</span>
          </el-form-item>

          <el-form-item label="营业执照:" v-if="info.info && info.info.type == 2">
            <el-image
              style="width: 100px; height: 100px"
              :src="info.info.business_license" 
              :preview-src-list="license"
              :zIndex="9999"
            />
          </el-form-item>

        </el-col>

        <el-col :sm="8">
          <el-form-item label="操作:">
            <el-radio-group v-model="form.is_status">
              <el-radio :label="2" :value="2">审核通过</el-radio>
              <el-radio :label="3" :value="3">审核拒绝</el-radio>
            </el-radio-group>
          </el-form-item>

          <el-form-item v-if="form.is_status=='3'" label="拒绝原因:" prop="refuse">
            <el-input v-model="form.refuse" label="拒绝原因"></el-input>
          </el-form-item>

          <!-- <el-form-item v-if="form.is_status=='2'" label="高级API:" prop="open_id">
            <open-select
              placeholder="请选择平台"
              v-model="form.open_id"
            />
          </el-form-item> -->

          <el-form-item v-if="form.is_status=='2'" label="类型:">
            <el-radio-group v-model="form.type" @change="updateType">
              <el-radio :label="1" :value="1">长期</el-radio>
              <el-radio :label="2" :value="2">包量</el-radio>
            </el-radio-group>
          </el-form-item>

          <el-form-item v-if="form.is_status=='2'" label="套餐:" prop="package_id" >
            <package-select
              ref="child"
              :type="form.type"
              placeholder="请选择套餐"
              v-model="form.package_id"
              @done='updateCount'
            />
          </el-form-item>
        </el-col>
      </el-row> 
    </el-form>
    <template v-slot:footer>
      <el-button @click="updateVisible(false)">取消</el-button>
      <el-button type="primary" :loading="loading" @click="save">
        保存
      </el-button>
    </template>
    
  </ele-modal>
 
</template>

<script>
  import PackageSelect from "@/views/package/list/components/package-select";
  import OpenSelect from  '@/views/open/components/open-select';
  import { info,check } from '@/api/account/list';
  const DEFAULT_FORM = {
    id:0,
    package_id: 0,
    type:1,
    is_status:2,
    //open_id:'',
    refuse:'',
    maturity_time: '',
  };

  export default {
    name: 'Check',
    components: { PackageSelect,OpenSelect },
    props: {
      // 弹窗是否打开
      visible: Boolean,
      // 修改回显的数据
      data:[]
    },
    data() {
      return {
        info:{
          telphone:'',
        },
        // 表单数据
        form: { ...DEFAULT_FORM },
        // 提交状态
        loading: false,
        // 是否是修改
        isUpdate: false,
        packages:[],
        opens:[],
        front:[],
        verso:[],
        license:[],
        packageShow: false,
      };
    },
    methods: {
      updateType(){
        this.packageShow = true;
        this.$refs.child.reload();

      },
      /* 更新visible */
      updateCount(object) {
        this.form.package_id = object.id;
        this.form.point = object.point;
        this.form.day = object.day;
        this.form.avatar_twin_count = object.avatar_twin_count;
        this.form.voice_twin_count = object.voice_twin_count;
        this.form.video_clip_count = object.video_clip_count;
      },
      openList(){
        openList({}).then((data) => {
          this.opens = data.list;
        }).catch((e) => {
          this.$message.error(e.message);
        });
      },
      /* 保存编辑 */
      save() {
        this.$refs['form'].validate((valid) => {
          if (!valid) {
            return false;
          }
          this.loading = true;
  
          const data = {
            ...this.form
          };
          
          check(data).then((msg) => {
            this.loading = false;
            this.$message.success(msg);
            this.updateVisible(false);
            this.$emit('done');
          }).catch((e) => {
            this.loading = false;
            this.$message.error(e.message);
          });
        });
      },
      /* 更新visible */
      updateVisible(value) {
        this.$emit('update:visible', value);
      }
    },
    watch: {
      visible(visible) {
        if (visible) {
          if (this.data) {
            info(this.data.id).then((rtn) => {
              this.info = rtn;

              if(this.info.info){
                this.front = [
                  this.info.info.id_card_front
                ];
                this.verso = [
                  this.info.info.id_card_verso
                ];
                this.license = [
                  this.info.info.business_license
                ];
              }
            }).catch((e) => {
              this.$message.error(e.message);
            });

            this.$util.assignObject(this.form, {
              ...this.data
            });
            this.isUpdate = true;
          } else {
            this.isUpdate = false;
         
          }
        } else {
          this.$refs['form'].clearValidate();
          this.form = { ...DEFAULT_FORM };
        }
      }
    }
  };
</script>
<style lang="scss" scoped>
.el-radio--medium.is-bordered {
    padding: 10px 20px 0 10px;
    border-radius: 4px;
    height: 36px;
    margin-bottom: 10px;
    margin-right: 10px;
}
</style>
